<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>8_2-使用JavaScript的方式实现动画效果</title>
</head>

<body>


    <h2>动画的本质是将元素的变化以渐变的方式完成</h2>
    <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
    <div id="Application">
        <div :style="{backgroundColor:'blue',width:width+'px',height:height+'px'}" @click="run"></div>
    </div>
    <script>
        const App = Vue.createApp({
            data() {
                return {
                    width: 100,
                    height: 100,
                    timer: null
                }
            },
            methods: {
                run() {
                    //https://www.runoob.com/js/js-timing.html
                    //setInterval() - 间隔指定的毫秒数不停地执行指定的代码。
                    this.timer = setInterval(this.animation, 10)
                },

                //回调函数
                animation() {
                    if (this.width == 200) {
                        //https://www.runoob.com/js/js-timing.html
                        //clearInterval() 方法用于停止 setInterval() 方法执行的函数代码。
                        clearInterval(this.timer)
                        return
                    } else {
                        this.width += 1
                        this.height += 1
                    }
                }
            }
        })
        App.mount("#Application")
    </script>
</body>

</html>